//
//  WDPersonalSettingViewCell.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/17.
//

#import "WDPersonalSettingViewCell.h"
#import "WDGrabOrdersPersonInfoTextView.h"
#import "WDGrabOrdersPersonInfoLabelView.h"


@interface WDPersonalSettingViewCell ()

@property (nonatomic, strong) TYZCommonCellModel *model;

@property (nonatomic, strong) WDGrabOrdersPersonInfoTextView *infoTextView;

@property (nonatomic, strong) WDGrabOrdersPersonInfoLabelView *infoLabelView;

@end

@implementation WDPersonalSettingViewCell


- (void)initWithSubViewCell {
    
}

- (void)initWithInfoTextView {
    if (!_infoTextView) {
        CGRect frame = CGRectMake(0, 0, kScreenW, kWDPersonalSettingViewCellHeight);
        _infoTextView = [[WDGrabOrdersPersonInfoTextView alloc] initWithFrame:frame];
        _infoTextView.titleFont = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
        _infoTextView.titleColor = [UIColor colorWithHexString:@"#000000"];
        _infoTextView.textAlignment = NSTextAlignmentRight;
        _infoTextView.valueFont = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
        _infoTextView.valueColor = [UIColor colorWithHexString:@"#000000"];
        [self.contentView addSubview:_infoTextView];
    }
    if (self.model) {
        _infoTextView.hidden = self.model.isIndicator;
        _infoTextView.title = self.model.title;
        _infoTextView.placeholder = self.model.placeholder;
        _infoTextView.valueTxtField.text = objectNull(self.model.value);
        _infoTextView.enabled = !self.model.isCheck;
    }
}

- (void)initWithInfoLabelView {
    if (!_infoLabelView) {
        CGRect frame = CGRectMake(0, 0, kScreenW, kWDPersonalSettingViewCellHeight);
        _infoLabelView = [[WDGrabOrdersPersonInfoLabelView alloc] initWithFrame:frame];
        _infoLabelView.titleFont = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
        _infoLabelView.titleColor = [UIColor colorWithHexString:@"#000000"];
        _infoLabelView.textAlignment = NSTextAlignmentRight;
        _infoLabelView.valueFont = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
        _infoLabelView.valueColor = [UIColor colorWithHexString:@"#000000"];
//        _infoLabelView.backgroundColor = [UIColor colorWithRandom];
        [self.contentView addSubview:_infoLabelView];
        @weakify(self);
        _infoLabelView.viewBlock = ^(id  _Nullable data) {
            @strongify(self);
            if (self.baseTableViewCellBlock) {
                self.baseTableViewCellBlock(self.model);
            }
        };
    }
    if (self.model) {
        _infoLabelView.hidden = !self.model.isIndicator;
        _infoLabelView.title = self.model.title;
        if ([objectNull(self.model.value) isEqualToString:@""]) {
            _infoLabelView.placeholder = self.model.placeholder;
        } else {
            _infoLabelView.value = self.model.value;
        }
    }
}

- (void)updateCellData:(id)cellEntity {
    self.model = cellEntity;
    
    [self initWithInfoTextView];
    
    [self initWithInfoLabelView];
    
    if (!self.model.isIndicator && !self.model.isSignal) {
        self.model.isSignal = YES;
        RAC(self.model, value) = self.infoTextView.valueTxtField.rac_textSignal;
    }
}


@end
